package com.Service.Impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.Dao.BaseDaoI;
import com.Entity.InviteMemberInfo;
import com.Service.InviteMemberService;

@Service("InviteMemberService")
public class InviteMemberServiceImpl extends BaseServiceImpl<InviteMemberInfo>
		implements InviteMemberService {

	@Autowired
	private BaseDaoI<InviteMemberInfo> inviteDao;

	private List<InviteMemberInfo> invitelist = new ArrayList<InviteMemberInfo>();

	@Override
	public List<InviteMemberInfo> findByID(int familyid, int userid) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("familyid", familyid);
		params.put("userid", userid);
		String hql = "from InviteMemberInfo t where t.familyId = :familyid and t.inviteUserId = :userid";
		invitelist = this.inviteDao.find(hql, params);
		if (null != invitelist && !invitelist.isEmpty()) {
			return invitelist;
		} else {
			return null;
		}
	}

	@Override
	public int deleteValidates(int familyid) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("familyid", familyid);
		String hql = "from InviteMemberInfo t where t.familyId = :familyid ";
		invitelist = this.inviteDao.find(hql, params);
		if (null != invitelist && !invitelist.isEmpty()) {
			for (int i = 0; i < invitelist.size(); i++) {
				this.inviteDao.delete(invitelist.get(i));
			}
			return 1;
		} else {
			return 0;
		}
	}

	@Override
	public List<InviteMemberInfo> getValidatesList(int userid) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("userid", userid);

		String hql = "from InviteMemberInfo t where t.inviteUserId = :userid";
		invitelist = this.inviteDao.find(hql, params);
		if (null != invitelist && !invitelist.isEmpty()) {
			return invitelist;
		} else {
			return null;
		}
	}

	@Override
	public List<InviteMemberInfo> getBackValidates(int userid) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("userid", userid);

		String hql = "from InviteMemberInfo t where t.userId = :userid";
		invitelist = this.inviteDao.find(hql, params);
		if (null != invitelist && !invitelist.isEmpty()) {
			return invitelist;
		} else {
			return null;
		}
	}

}
